import java.util.Arrays;
import java.util.Scanner;

/**
 * @author gao
 * @date 2025/9/28 10:39
 */

public class Solution {
    public int largestPerimeter(int[] nums) {
        Arrays.sort(nums);
        int perimeter = 0;
        for (int fix = nums.length - 1; fix >= 2; fix--) {
            if (nums[fix - 2] + nums[fix - 1] > nums[fix]) {
                perimeter = nums[fix] + nums[fix - 1] + nums[fix - 2];
                return perimeter;
            }
        }
        return 0;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            int n = in.nextInt();
            int[] nums = new int[n];
            for (int i = 0; i < nums.length; i++) {
                nums[i] = in.nextInt();
            }
            Solution solution = new Solution();
            System.out.println(solution.largestPerimeter(nums));
        }
    }
}